package com.ccc.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.ccc.dao.OrderinfoDao;
import com.ccc.model.Orderinfo;
import com.ccc.model.User;
import com.ccc.util.dao.UtilDao;

@Component("orderinfoDao")
public class OrderinfoDaoImpl implements OrderinfoDao {
	private UtilDao utilDao;

	@Override
	public void addOrderinfo(Orderinfo orderinfo) {
		utilDao.save(orderinfo);
	}

	@Override
	public void deleteOrderinfo(Orderinfo orderinfo) {
		utilDao.delete(orderinfo);
	}

	@Override
	public void updateOrderinfo(Orderinfo orderinfo) {
		utilDao.update(orderinfo);
	}
	
	@Override
	public void orderinfoChange(Orderinfo orderinfo, Integer status){
		orderinfo.setStatus(status);
		utilDao.update(orderinfo);
	}

	@Override
	public Orderinfo findOrderinfo(int id) {
		return utilDao.find(Orderinfo.class, id);
	}

	public UtilDao getUtilDao() {
		return utilDao;
	}

	@Resource
	public void setUtilDao(UtilDao utilDao) {
		this.utilDao = utilDao;
	}

	@Override
	public List<Orderinfo> findOrderinfo(String hql, Object[] o) {
		return utilDao.find(hql, o);
	}

	@Override
	public Long[] SumSendAndReceived(Integer toUserId, Integer currentTime) {
		return utilDao.sums("select SUM(oi.productCount) from Orderinfo oi where oi.order.toUserId = ? and oi.order.orderTime <= ?", new Object[]{toUserId, currentTime},
				"select SUM(oi.deliverCount) from Orderinfo oi where oi.order.toUserId = ? and oi.order.orderTime <= ?", new Object[]{toUserId, currentTime});
	}

}
